<?php

namespace Api\Library;

class Send {

    /**
     * 发送聊天消息
     * 
     * @param string $messageType Chat/Text/Friends || Chat/TopicLink/Topic
     * @param type $fromUser 510
     * @param type $fromUserName
     * @param type $fromUserAvatar
     * @param type $groupId
     * @param type $groupName
     * @param type $groupAvatar
     * @param type $toUser 510
     * @param type $text [消息]
     * @param type $fileSize [{link_url,link_img,link_title,link_info,link_time}, ...]
     * @return type 未知
     */
    static function message($messageType, $fromUser, $fromUserName, $fromUserAvatar, $groupId, $groupName, $groupAvatar, $toUser, $text, $fileSize) {
        import('@.Library.IMPack');
        $obj = new IMPack();
        $service_port = C('PORT');
        $address = C('ADDRESS');
        $extentsionFields = array();

        //撤销
        $extentsionFields['msgId'] = '';                                   // 撤销ID唯一
        //时间
        $extentsionFields['clientSendTime'] = date("Y-m-d H:i:s");         // 客户端发送时间
        $extentsionFields['serverReceiveTime'] = '';                       // 服务器端接收时间-
        $extentsionFields['serverPushTime'] = '';                          // 服务端推送时间-
        $extentsionFields['clientReceiveTime'] = '';                       // 客户端接收-
        //推送
        $extentsionFields['expireTime'] = '';                              // 设置超期时间-
        $extentsionFields['appKey'] = C('APP_KEY');                        // 应用标识
        $extentsionFields['fromUser'] = $fromUser;                         // 发送用户*
        $extentsionFields['fromUserName'] = $fromUserName;                 // 发送用户名*
        $extentsionFields['fromUserAvatar'] = $fromUserAvatar;             // 发送用户头像*
        $extentsionFields['fromUserInfo'] = '';                            // 发送用户信息-
        $extentsionFields['fromDeviceId'] = '';                            // 发送设备Id-
        $extentsionFields['toUser'] = $toUser;                             // 接收用户*
        // 群
        $extentsionFields['groupId'] = $groupId;                           //发送群名称-
        $extentsionFields['groupName'] = $groupName;                       //发送群名称-
        $extentsionFields['groupAvatar'] = $groupAvatar;                   //发送群头像-
        $extentsionFields['groupInfo'] = '';                               //发送群资料-
        //消息
        $extentsionFields['messageAlert'] = '';                            // 消息提醒-
        $extentsionFields['messageType'] = $messageType;                   // 消息类型*
        // 		$extentsionFields['messageBody']= '';              // 消息内容*

        $headstr = $obj::createPackHead(time(), '1800', '0', $extentsionFields);
        $bodystr = $obj::createChatMsgBody($text, '', '', '', '', json_encode($fileSize));  //通知BODY
        $ret = $obj::sendMsg($address, $service_port, $headstr, $bodystr, '');
        $obj::unPacket($ret, $head, $body, $attachment);
        return json_decode($head, TRUE);
    }

}
